#include "Math.h"

#include <cstdlib>

using namespace std;

const float Math::PI = 3.14159265359f;

/********************************************************************************************************
Constructor & Destructor
********************************************************************************************************/

//Default Constructor
Math::Math(){
	
}

Math::~Math(){

}


float Math::factorial(float val)
{
	return ((val <= 1) ? 1 : (val * factorial(val - 1)));
}

float Math::binominialCoefficient(int i, int j)
{
	if(factorial((float)(j)) * factorial((float)(i - j)) == 0)
		return 0;
	return ((float)(factorial((float)(i))) / (float)(factorial((float)(j)) * factorial((float(i - j)))));
}


float Math::bernsteinPolynomial(int nbPoints, float t, int numPoint)
{
	float newPoint = 0;

	//for(int i = 0; i < nbPoints; ++i)
	{
		newPoint += Math::binominialCoefficient(nbPoints -1, numPoint) * pow(1-t, nbPoints -1 - numPoint) * pow(t, numPoint);
	}

	return newPoint;
}


float Math::RandFloat(float a, float b)
{
	return ((b-a)*((float)rand()/RAND_MAX))+a;
}